package com.frinder.seata.order.service;

import com.frinder.seata.data.base.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @ClassName CallAccountFallbackFactory
 * @Description 远程扣减余额服务熔断机制
 * @Author frinder
 * @Date 2020/8/18 16:01
 * @Verion 1.0
 */
@Slf4j
@Component
public class CallAccountFallbackFactory implements FallbackFactory<CallAccountService> {
    @Override
    public CallAccountService create(Throwable e) {
        return new CallAccountService() {
            @Override
            public Result decrease(boolean timeout, long userId, BigDecimal money, long orderId, boolean circle) {
                log.error("扣减账户余额服务熔断生效，客户[{}]，扣减金额[{}]，订单[{}]，失败原因[{}]",
                        userId, money, orderId, e.getMessage());
                return Result.selfFail(e.getMessage());
            }
        };
    }
}
